package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JEditorPane;
import javax.swing.JTextPane;
import java.awt.TextArea;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerPrincipal;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ResourceBundle.Control;
import javax.swing.ImageIcon;

public class TelaCadastrarConsultas extends JFrame {

	private JPanel contentPane;
	static JTextField txt_dataConsulta;
	static JTextField txt_hospitalClinica;
	static JTextField txt_dataVolta;
	static JTextField txt_medico;
	static TextArea textDiagnostico;
	static Integer codAletrar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastrarConsultas frame = new TelaCadastrarConsultas();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaCadastrarConsultas() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 840, 540);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblConsultaMdica = new JLabel("Consulta M\u00E9dica");
		lblConsultaMdica.setForeground(new Color(0, 0, 128));
		lblConsultaMdica.setFont(new Font("Franklin Gothic Medium Cond", Font.PLAIN, 25));
		lblConsultaMdica.setBounds(38, 27, 169, 34);
		contentPane.add(lblConsultaMdica);
		
		JLabel lblDataDaConsulta = new JLabel("Data da Consulta:");
		lblDataDaConsulta.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDaConsulta.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDaConsulta.setBounds(117, 92, 124, 19);
		contentPane.add(lblDataDaConsulta);
		
		txt_dataConsulta = new JTextField();
		txt_dataConsulta.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataConsulta.setBounds(251, 89, 124, 23);
		contentPane.add(txt_dataConsulta);
		txt_dataConsulta.setColumns(10);
		
		JLabel lblHospitalclnica = new JLabel("Hospital/Cl\u00EDnica:");
		lblHospitalclnica.setHorizontalAlignment(SwingConstants.RIGHT);
		lblHospitalclnica.setFont(new Font("Arial", Font.PLAIN, 14));
		lblHospitalclnica.setBounds(117, 125, 124, 19);
		contentPane.add(lblHospitalclnica);
		
		txt_hospitalClinica = new JTextField();
		txt_hospitalClinica.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_hospitalClinica.setColumns(10);
		txt_hospitalClinica.setBounds(251, 122, 380, 23);
		contentPane.add(txt_hospitalClinica);
		
		JLabel lblDiagnstico = new JLabel("Diagn\u00F3stico:");
		lblDiagnstico.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDiagnstico.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDiagnstico.setBounds(117, 193, 124, 19);
		contentPane.add(lblDiagnstico);
		
		JLabel lblDataDaVolta = new JLabel("Data da Volta:");
		lblDataDaVolta.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDaVolta.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDaVolta.setBounds(117, 379, 124, 19);
		contentPane.add(lblDataDaVolta);
		
		txt_dataVolta = new JTextField();
		txt_dataVolta.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataVolta.setColumns(10);
		txt_dataVolta.setBounds(251, 377, 124, 23);
		contentPane.add(txt_dataVolta);
		
		textDiagnostico = new TextArea();
		textDiagnostico.setBounds(251, 193, 380, 160);
		contentPane.add(textDiagnostico);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String dataConsulta = txt_dataConsulta.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String diagnostico = textDiagnostico.getText();
				String dataVolta = txt_dataVolta.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				control.InserirConsultas(dataConsulta, local, medico, diagnostico, dataVolta);
				TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
				telaMensagem.setLocationRelativeTo(null);
				telaMensagem.setVisible(true);
				txt_dataConsulta.setText("");
				txt_hospitalClinica.setText("");
				txt_medico.setText("");
				textDiagnostico.setText("");
				txt_dataVolta.setText("");
			}
		});
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSalvar.setBounds(491, 426, 100, 43);
		contentPane.add(btnSalvar);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSair.setBounds(601, 426, 100, 43);
		contentPane.add(btnSair);
		
		txt_medico = new JTextField();
		txt_medico.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_medico.setColumns(10);
		txt_medico.setBounds(251, 155, 380, 23);
		contentPane.add(txt_medico);
		
		JLabel lblMdico = new JLabel("M\u00E9dico:");
		lblMdico.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMdico.setFont(new Font("Arial", Font.PLAIN, 14));
		lblMdico.setBounds(117, 158, 124, 19);
		contentPane.add(lblMdico);
		
		JButton button_2 = new JButton("Deletar");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataConsulta = txt_dataConsulta.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String diagnostico = textDiagnostico.getText();
				String dataVolta = txt_dataVolta.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.deletarConsuta(codAletrar, dataConsulta, local, medico, diagnostico, dataVolta);
					TelaMensagemDeletar telaMensagem = new TelaMensagemDeletar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataConsulta.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					textDiagnostico.setText("");
					txt_dataVolta.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_2.setBackground(Color.WHITE);
		button_2.setBounds(381, 426, 100, 43);
		contentPane.add(button_2);
		
		JButton btnAlterar = new JButton("Alterar");
		btnAlterar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataConsulta = txt_dataConsulta.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String diagnostico = textDiagnostico.getText();
				String dataVolta = txt_dataVolta.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.editarConsulta(codAletrar, dataConsulta, local, medico, diagnostico, dataVolta);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataConsulta.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					textDiagnostico.setText("");
					txt_dataVolta.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		btnAlterar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnAlterar.setBackground(Color.WHITE);
		btnAlterar.setBounds(269, 426, 100, 43);
		contentPane.add(btnAlterar);
		
		JButton btnListar = new JButton("Listar");
		btnListar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaListarConsultas telaListaConsulta = new TelaListarConsultas();
				telaListaConsulta.setLocationRelativeTo(null);
				telaListaConsulta.setVisible(true);
			}
		});
		btnListar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnListar.setBackground(Color.WHITE);
		btnListar.setBounds(159, 426, 100, 43);
		contentPane.add(btnListar);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\FundoCadastros.png"));
		label.setBounds(0, 0, 834, 509);
		contentPane.add(label);
	}
}
